package com.huasoft.servlet.userself;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.huasoft.dao.FileDao;
import com.huasoft.dao.UserFileDao;
import com.huasoft.domain.File;
import com.huasoft.domain.UserFile;

public class BackFileServlet {
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		UserFile userfile = new UserFile();
		userfile.setId(Integer.parseInt(request.getParameter("id")));
		String status = request.getParameter("status");
		status = new String(status.getBytes("iso8859-1"), "gbk");
		userfile.setGiveStatus(status);
		UserFileDao userFileDao = new UserFileDao();
		boolean check = userFileDao.checkedFile(userfile);
		if (check) {
			FileDao fileDao = new FileDao();
			File file = new File();
			file.setId(userFileDao.getFileIdById(userfile));
			file.setStatus("可借阅");
			boolean m = fileDao.updateStatus(file);
			if (m) {
				request.setAttribute("msg_backFileSuccess", "归还成功");
			} else {
				request.setAttribute("msg_backFileFalse", "归还失败");
			}
		} else {
			request.setAttribute("msg_backFileFalse", "归还失败");
		}
		request.getRequestDispatcher("/index.jsp").forward(request, response);
	}
}
